package com.lzw.controller.maintenance;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.anno.Log;
import com.lzw.pojo.RepairRequest;
import com.lzw.service.maintenance.MRS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/MR")
public class MRC {

    @Autowired
    private MRS mrs;

    @GetMapping("/list")
    public PageInfo<RepairRequest> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate requestDate){
        PageHelper.startPage(pageNum,pageSize);
        List<RepairRequest> list = mrs.list(pageNum,pageSize,requestDate);
        return new PageInfo<>(list);
    }

    @PutMapping("update")
    @Log
    public String update(@RequestBody RepairRequest repairRequest){
        mrs.update(repairRequest);
        return "处理成功";
    }
}
